<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
  <meta name="generator" content=
  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">

  <title>break</title>
  <link href="../cppreference.css" rel="stylesheet" type="text/css">
</head>

<body>
<table>
  <tr>
  <td>
  <div class="body-content">

  <div class="header-box">
    <a href="../index.html">cppreference.com</a> &gt; <a href=
    "index.html">C/C++ Keywords</a> &gt; <a href="break.html">break</a>
  </div>

  <div class="name-format">
    break
  </div>

  <p>The break keyword is used to break out of a <a href=
  "do.html">do</a>, <a href="for.html">for</a>, or <a href=
  "while.html">while</a> loop. It is also used to finish each clause of
  a <a href="switch.html">switch</a> statement, keeping the program
  from &quot;falling through&quot; to the next case in the code. An
  example:</p>
  <pre class="example-code">
   while( x &lt; 100 ) {
     if( x &lt; 0 )
       break;
     cout &lt;&lt; x &lt;&lt; endl;
     x++;
   }            
</pre>

  <p>A given break statement will break out of only the closest loop,
  no further. If you have a triply-nested for loop, for example, you
  might want to include extra logic or a <a href="goto.html">goto</a>
  statement to break out of the loop.</p>

  <div class="related-name-format">
    Related topics:
  </div>

  <div class="related-content">
    <a href="continue.html">continue</a><br>
    <a href="do.html">do</a><br>
    <a href="for.html">for</a><br>
    <a href="goto.html">goto</a><br>
    <a href="switch.html">switch</a><br>
    <a href="while.html">while</a>
  </div>
  </div>
  </td>
  


  </tr>
  </table>
</body></html>
